﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ACP.DTO;

namespace ACP.Data
{
    public class TempExamRepository : Repository<tempexam>
    {
        public static void InsertQuestionAnswer(tempexam tempExam)
        {
            Repository<tempexam> tempexamRepository = new Repository<tempexam>();
            try
            {
                tempexamRepository.Add(tempExam);
                tempexamRepository.UnitOfWork.Commit();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                tempexamRepository.Dispose();
            }
        }

        public static void UpdatetAnswer(tempexam tempexamObject)
        {
            Repository<tempexam> tempexamsRepository = new Repository<tempexam>();
            try
            {
                tempexamsRepository.Update(tempexamObject);
                tempexamsRepository.UnitOfWork.Commit();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                tempexamsRepository.Dispose();
            }
        }

        public static tempexam GettempexamById(int testId, int questionId)
        {
            IRepository<tempexam> tempexamsRepository = new Repository<tempexam>();
            tempexam tempexamEntity;
            try
            {
                tempexamEntity = tempexamsRepository.First(q => q.TestId == testId && q.QuestionId==questionId);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                tempexamsRepository.Dispose();
            }
            return tempexamEntity;
        }

        public static List<tempexam> GetExamQuestionAndAnswersByTestId(int testId)
        {
            Repository<tempexam> tempexamsRepository = new Repository<tempexam>();
            List<tempexam> lsttempexamEntity;
            try
            {
                lsttempexamEntity = tempexamsRepository.FindWithInclude(q => q.TestId == testId,"question").ToList();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                tempexamsRepository.Dispose();
            }
            return lsttempexamEntity;
        }

        public static void InsertUnAnsweredQuestions(List<tempexam> lstTempExams)
        {
            Repository<tempexam> tempexamRepository = new Repository<tempexam>();
            try
            {
                tempexamRepository.AddObjects(lstTempExams);
                tempexamRepository.UnitOfWork.Commit();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                tempexamRepository.Dispose();
            }
        }
    }
}
